<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\LinkPager;
use kartik\file\FileInput;


$this->title = '房间人员列表';
$this->params['breadcrumbs'][] = $this->title;

//名单模板
$template = yii::$app->params['template'];

?>
<style type="text/css">
    .table > thead > tr > th{vertical-align: middle;text-align: center;}
    .table > tbody > tr > td{vertical-align: middle;text-align: center;}
    .cancel{background-color:#e9e5e5;}
    .cs1{margin:5px;}
</style>
<div class="room-use-index">

    <h2 class="page-header">
        <small><?= Html::encode($this->title) ?></small>
        <div class="pull-right" style="display: inline-block;">
            <?= Html::a('创建房间', ['create'], ['class' => 'btn btn-success']) ?>
            <div style="display: inline-block;">
            <?php echo FileInput::widget([
                  'language' => 'zh',
                  'name' => 'excel',
                  'id' => 'file-upload',
                  'pluginOptions' => [
                      'uploadUrl' => "/cruise/room-use/import-cut",
                      'uploadExtraData' => [
                          '_csrf' => Yii::$app->getRequest()->getCsrfToken(),
                      ],
                      'showPreview' => false,
                      'showCaption' => false,
                      'showRemove' => false,
                      'showUpload' => false,
                      'uploadAsync'=> true,
                      'maxFileCount' => 1,
                      'browseClass' => 'btn btn-warning',
                      'browseIcon' => '',
                      'browseLabel' => '上传人员',
                      'fileTypeSettings' => [],
                  ],
                  'options' => ['accept' => '', 'multiple'=>false],
                  ]);?>
            </div>
            <a class="btn btn-primary" href="/download/template2.xlsx" >下载导入人员模板</a>      
        </div>  
    </h2> 
    <div class="page-header" style="height: 40px">  
        <?= Html::a('分房号', ['/cruise/deck/index?cruise_id=1'], ['class' => 'btn btn-primary','target'=>'_blank']) ?>
        <?= Html::a('下载表格', ['/cruise/room-use/down-list?cruise_id=1'], ['class' => ' btn btn-info','target'=>'_blank']) ?>
        <?=Html::a('生成名单','javascript:;',["data-cruise-id"=>1,"class"=>"btn btn-success create_excel",])?>
         <?= Html::a('签证办理表格', ['/cruise/customer/visa-excel'], ['class' => ' btn btn-primary','target'=>'_blank']) ?>
        <?= Html::a('删除人员', ['/cruise/customer/list-delete'], ['class' => ' btn btn-danger','target'=>'_blank']) ?>
        <?= Html::a('取消人员', ['/cruise/customer/cancel-list'], ['class' => ' btn btn-warning','target'=>'_blank']) ?>
        <?= Html::a('取消人员表格', ['/cruise/customer/cancel-excel'], ['class' => ' btn btn-success','target'=>'_blank']) ?>

        <?= Html::a('未签到人员表格', ['/cruise/customer/unsign-excel'], ['class' => ' btn btn-info','target'=>'_blank']) ?>
    </div>
    <p>
        <?php echo $this->render('_search', ['model' => $searchModel]); ?>
    </p>

    <table class="table table-bordered" style="margin-top:15px;font-size:12px;">
        <thead>
            <tr><th rowspan="2">房间名称</th> <th rowspan="2">房间号</th><th rowspan="2">备注</th><th rowspan="2">下载状态</th><th colspan="10">入住人信息</th><th rowspan="2">添加人员</th><th rowspan="2">操作</th></tr>
            <tr><th>姓名</th><th>性别</th><th>出生日期</th><th>手机号</th><th>备注</th><th>团号</th><th>体系</th><th>签到</th><th>是否取消</th><th>操作</th></tr>
        </thead>

        <tbody>
            <?php foreach($dataProvider->getModels() as $model){ ?>
                <?php $cnum = $model->customerNum; ?>

                <?php if($cnum >= 1){ ?>
                <tr>
                   <td class="col-md-1" rowspan="<?=$cnum+1?>"><?=$model->room->name.' '.$model->room->code. ' '.$model->num.'人间';?></td> 
                   <td rowspan="<?=$cnum+1?>"><?=$model->code?></td>
                   <td rowspan="<?=$cnum+1?>"><?=$model->remark?></td>
                   <td rowspan="<?=$cnum+1?>"><?=Yii::$app->params['download'][$model->download]?></td>
                   <td colspan="10" style="padding: 0;border:0;height: 0;border-bottom-style: hidden;"> 
                   </td> 
                   <td rowspan="<?=$cnum+1?>"><?php  $url = sprintf("/cruise/customer/create?room_use_id=%d", $model->id);
                    $str =  Html::a('添加人员',$url,['title' => '添加人员','class'=>'btn btn-info btn-xs cs1', 'target'=>'_blank']); echo $str;?></td>
                   <td rowspan="<?=$cnum+1?>"><?php  
                    $url2 = sprintf("/cruise/room-use/view?id=%d", $model->id);
                    $url3 = sprintf("/cruise/room-use/update?id=%d", $model->id);
                    $str2 =  Html::a('查看房间',$url2,['title' => '查看房间','class'=>'btn btn-primary btn-xs cs1', 'target'=>'_blank']).Html::a('编辑房间',$url3,['title' => '编辑房间','class'=>'btn btn-success btn-xs cs1','target'=>'_blank']);
                    echo $str2;?></td>
                </tr> 
                <?php foreach($model->customer as $customer){ ?>
                <tr  class="<?=($customer->cancel == 3)?'cancel':''?>">
                    <td><?=$customer->first_name.$customer->last_name?></td>
                    <td><?=isset(Yii::$app->params['gender'][$customer->gender])?Yii::$app->params['gender'][$customer->gender]:''?></td>
                    <td class="col-md-1"><?=$customer->birthday?></td>
                    <td class="col-md-1"><?=$customer->phone?></td>
                    <td><?=$customer->remark?></td>
                    <td><?=$customer->group?></td>
                    <td><?=$customer->supply?></td>
                    <td><?=isset(yii::$app->params['sign'][$customer->sign]) ? yii::$app->params['sign'][$customer->sign] : '' ?></td>
                    <td><?=isset(yii::$app->params['cancel'][$customer->cancel]) ? yii::$app->params['cancel'][$customer->cancel] : '' ?></td>
                    <td><?php  
                    $url_1 = sprintf("/cruise/customer/view?id=%d", $customer->id);
                    $url_2 = sprintf("/cruise/customer/update?id=%d", $customer->id);
                    $url_3 = sprintf("/cruise/customer/change?id=%d", $customer->id);
                    $str_3 =  Html::a('查看人员',$url_1,['title' => '查看人员','class'=>'btn btn-primary btn-xs cs1','target'=>'_blank']).Html::a('编辑人员',$url_2,['title' => '编辑人员','class'=>'btn btn-success btn-xs cs1','target'=>'_blank']).Html::a('变更房间',$url_3,['title' => '变更房间','class'=>'btn btn-warning btn-xs cs1', 'data-toggle'=>'modal', 'data-target'=>'.change-modal']);
                    echo $str_3;?>
                        
                    </td>
                   
                </tr>    
                <?php }?>   
                 
                <?php }else if($cnum == 0){ ?>
                <tr>
                   <td><?=$model->room->name.' '.$model->room->code. ' '.$model->num.'人间';?></td> 
                   <td><?=$model->remark?></td>
                   <td><?=$model->code?></td>
                   <td><?=Yii::$app->params['download'][$model->download]?></td>
                   <td colspan="10"></td>
                   <td><?php  $url = sprintf("/cruise/customer/create?room_use_id=%d", $model->id);
                    $str =  Html::a('添加人员',$url,['title' => '添加人员','class'=>'btn btn-info btn-xs cs1', 'target'=>'_blank']); echo $str;?></td>
                   <td><?php  
                    $url2 = sprintf("/cruise/room-use/view?id=%d", $model->id);
                    $url3 = sprintf("/cruise/room-use/update?id=%d", $model->id);
                    $str2 =  Html::a('查看房间',$url2,['title' => '查看房间','class'=>'btn btn-primary btn-xs cs1', 'target'=>'_blank']).Html::a('编辑房间',$url3,['title' => '编辑房间','class'=>'btn btn-success btn-xs cs1','target'=>'_blank']);
                    echo $str2;?>
                        
                    </td>
                <tr> 
                <?php }?>    
            <?php }?> 
        </tbody>    
    </table>


    <?= LinkPager::widget(['pagination' => $dataProvider->pagination]); ?>

</div>

<!-- 选择游轮模板名单 -->
<div class="modal fade cruise-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog " role="document">
      <div class="modal-content">
           
            <input type="hidden" name="cruise_id" id="cruise_id" value="">
            <ul class="list-group">
                <li class="list-group-item" style="background-color:#666;color:#FFF;">选择名单模板</li>
                <?php foreach($template as $k=>$v){ ?>
                <li class="list-group-item"><label><input type="radio" name="template_id" value="<?= $k?>"> <?= $v ?></label></li>
                <?php } ?>
                <li class="list-group-item"><button class="btn btn-primary" id="create">确定 </button></li>
            </ul>
            
      </div>
  </div>
</div>

<div class="modal fade change-modal"   role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog " role="document" style="width: 800px;">
      <div class="modal-content">

      <!-- 嵌入内容 --> 
    </div>
  </div>
</div>


<?=  yii\web\View::registerJsFile("/js/layer/layer.js",['depends' => 'app\assets\AppAsset']) ?>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

  // 清除模态框缓存
$(".change-modal").on("hidden.bs.modal", function() {
  $(this).removeData("bs.modal");
  window.location.reload();
});

  $('#file-upload').on('filebatchselected', function(event, files) {
      $(this).fileinput("upload");
  });

  $('#file-upload').on('fileuploaded', function(event, data, previewId, index) {
      var response = data.response;
      if(response.code == 'error'){
          layer.msg(response.message);
          window.location.reload();
          return false;
      }else if(response.code == 'ok'){
          layer.msg(response.message);
          window.location.reload();
          return false;
      }
  });


   $(".cruise-modal").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
    });

  $(".create_excel").click(function(){
       $('.cruise-modal').modal('show');
       var cruise_id = $(this).attr("data-cruise-id");
       $("#cruise_id").val(cruise_id);
  });

  $("#create").click(function(){
      var cruise_id = $("#cruise_id").val();
      var template_id = $("input[name='template_id']:checked").val();
      if(!template_id){
          alert("未选择名单模板");
          return false;
      }
      var url = "/cruise/customer/create-excel?cruise_id="+cruise_id+"&template_id="+template_id;
      window.open(url);

  });
</script>
<?php app\components\JsBlock::end() ?>  